package com.marvels.approve.credit.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.dragon.app.ykd.service.ClientAppService;
import com.fintech.common.vo.FintechResult;
import com.fintech.third.model.credit.BRDeviceInfo;
import com.fintech.third.model.credit.CallCountFilterDto;
import com.fintech.third.model.credit.CreditReportMessageDto;
import com.fintech.third.model.credit.CreditReportPortrait;
import com.fintech.third.model.credit.EdcDeviceDto;
import com.fintech.third.model.credit.MxAlipayAddressDto;
import com.fintech.third.model.credit.MxAlipayBankDto;
import com.fintech.third.model.credit.MxAlipayUserInfoDto;
import com.fintech.third.model.credit.MxOperatorReportDto;
import com.fintech.third.model.credit.PieChartDto;
import com.fintech.third.model.credit.YDDeviceLinkDto;
import com.fintech.third.model.credit.YDLendBehaviorDto;
import com.fintech.third.model.credit.YDUserInfoDto;
import com.fintech.third.model.moxie.carriesv2.MXCheckSearchInfo;
import com.fintech.third.model.moxie.dataprovide.IntMxAccountBaseInfo;
import com.fintech.third.model.shzx.EdcZxPersonalNewCredit;
import com.fintech.third.service.credit.CreditReportService;
import com.marvels.approve.credit.service.ApproveThirdCreditReportService;
import com.marvels.approve.loan.dao.IMcamLoanApplyInfoDao;
import com.marvels.approve.loan.dto.McamLoanApplyInfoDTO;
import com.marvels.common.utils.MarvelsLogUtil;

@Component
public class ApproveThirdCreditReportServiceImpl implements ApproveThirdCreditReportService{

	@Autowired
	private CreditReportService creditReportService;
	@Autowired
	ClientAppService clientAppService;
	
	@Autowired
	private IMcamLoanApplyInfoDao imcamLoanApplyInfoDao;
	
	@Override
	public IntMxAccountBaseInfo getUserOperatorSummary(String loanId) {
		return creditReportService.getUserOperatorSummary(loanId);
	}

	@Override
	public List<PieChartDto> selectCallLocationPercent(String loanId) {
		return creditReportService.selectCallLocationPercent(loanId);
	}

	@Override
	public List<PieChartDto> selectCallTypePercent(String loanId) {
		return creditReportService.selectCallTypePercent(loanId);
	}
	
	@Override
	public CallCountFilterDto getCallCount(String loanId) {
		return creditReportService.getCallCount(loanId);
	}
	
	@Override
	public CallCountFilterDto getCallCountWithMonth(String loanId,String month) {
		return creditReportService.getCallCountWithMonth(loanId,month);
	}

	@Override
	public CallCountFilterDto getStrangerNumberStatistics(String loanId, String userId) {
		return creditReportService.getStrangerNumberStatistics(loanId, userId);
	}

	@Override
	public CallCountFilterDto getCallPeriodStatistics(String loanId) {
		return creditReportService.getCallPeriodStatistics(loanId);
	}

	@Override
	public CallCountFilterDto getCallPeriodStatisticsWithMonth(String loanId, String month) {
		return creditReportService.getCallPeriodStatisticsWithMonth(loanId, month);
	}

	@Override
	public CreditReportMessageDto queryCallCountList(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return creditReportService.queryCallCountList(map);
	}

	@Override
	public CreditReportMessageDto queryCallCountListWithMonth(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return creditReportService.queryCallCountListWithMonth(map);
	}

	@Override
	public CreditReportMessageDto getCallDetailList(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return creditReportService.getCallDetailList(map);
	}

	@Override
	public CreditReportMessageDto getAddressBookList(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return creditReportService.getAddressBookList(map);
	}

	@Override
	public MxAlipayUserInfoDto getMxAlipayUserInfo(String loanId) {
		// TODO Auto-generated method stub
		return creditReportService.getMxAlipayUserInfo(loanId);
	}

	@Override
	public List<MxAlipayBankDto> getMxAlipayBankList(String loanId) {
		// TODO Auto-generated method stub
		return creditReportService.getMxAlipayBankList(loanId);
	}

	@Override
	public List<MxAlipayAddressDto> getMxAlipayAddressList(String loanId) {
		// TODO Auto-generated method stub
		return creditReportService.getMxAlipayAddressList(loanId);
	}

	@Override
	public CreditReportMessageDto getZXApplyInfo(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return creditReportService.getZXApplyInfo(map);
	}

	@Override
	public CreditReportPortrait getZXBasicInfo(String cardNo) {
		// TODO Auto-generated method stub
		return creditReportService.getZXBasicInfo(cardNo);
	}

	@Override
	public CreditReportMessageDto getZXOrderInfo(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return creditReportService.getZXOrderInfo(map);
	}

	@Override
	public CreditReportMessageDto getZXOrderDetailInfo(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return creditReportService.getZXOrderDetailInfo(map);
	}

	
	public McamLoanApplyInfoDTO  queryByLoandId(String loanId) {
		return imcamLoanApplyInfoDao.queryByLoandId(loanId);
	}

	@Override
	public MxOperatorReportDto getMxCheckBlackInfo(String loanId) {
		// TODO Auto-generated method stub
		return creditReportService.getMxCheckBlackInfo(loanId);
	}

	@Override
	public MXCheckSearchInfo getMxUserSearchInfo(String loanId) {
		return creditReportService.getMxUserSearchInfo(loanId);
	}

	@Override
	public String getThirdLoanId(String virLaonId) {
		try {
		FintechResult result = clientAppService.getThirdLoanId(virLaonId);
		MarvelsLogUtil.getInstance().info("获取复贷loanId成功，loanId="+virLaonId+",data="+JSON.toJSONString(result));
		if(result.getData() != null)
			return result.getData().toString();
		else
			return virLaonId;
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取复贷loanId失败，loanId="+virLaonId, e);
			return virLaonId;
		}
	}

	@Override
	public BRDeviceInfo getDeviceInfo(Map<String,Object> map) {
		String reloadId = getThirdLoanId((String)(map.get("loanId")));
		EdcDeviceDto dto = creditReportService.selectByLoanId(reloadId);
		BRDeviceInfo dto1 = creditReportService.getDeviceInfo(map);
		if(dto1 == null)
			dto1 = new BRDeviceInfo();
		if(dto!= null) {
			dto1.setAppCt(dto.getAppCt());
			dto1.setApps(dto.getApps());
			dto1.setOperator(dto.getOperator());
			dto1.setNetType(dto.getNetType());
			dto1.setRoot(dto.getRoot());
			dto1.setVpn(dto.getVpn());
			if("CMCC".equals(dto1.getQinfo_carrier_name()))
				dto1.setQinfo_carrier_name("中国移动");
			else if("CUCC".equals(dto1.getQinfo_carrier_name()))
				dto1.setQinfo_carrier_name("中国联通");
			else if("CTCC".equals(dto1.getQinfo_carrier_name()))
				dto1.setQinfo_carrier_name("中国电信");
		}
		return dto1;
	}

	@Override
	public CreditReportMessageDto getDeviceDetailInfo(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return creditReportService.getDeviceDetailInfo(map);
	}

	@Override
	public YDUserInfoDto selectYDUserInfoDto(String loanId) {
		// TODO Auto-generated method stub
		return creditReportService.selectYDUserInfoDto(loanId);
	}

	@Override
	public YDLendBehaviorDto selectYDLendBehaviorDto(String loanId) {
		// TODO Auto-generated method stub
		return creditReportService.selectYDLendBehaviorDto(loanId);
	}

	@Override
	public YDDeviceLinkDto selectYDDeviceLinkDto(String loanId) {
		// TODO Auto-generated method stub
		return creditReportService.selectYDDeviceLinkDto(loanId);
	}

	@Override
	public EdcZxPersonalNewCredit getZXNewCredit(String loanId) {
		// TODO Auto-generated method stub
		return creditReportService.getZXNewCredit(loanId);
	}


}
